package com.example.servlet.collection;

import com.alibaba.fastjson.JSON;
import com.example.model.Collection;
import com.example.service.CollectionService;
import com.example.service.impl.CollectionServiceImpl;
import com.example.vo.Page;
import com.example.vo.ResponseData;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * 分页显示虚拟商品
 */
@WebServlet("/CollectionServlet/queryByCondition")
public class QueryPageServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/json;charset=utf-8");
        String cname = req.getParameter("cname");
        String cstate = req.getParameter("cstate");
        String currentPage = req.getParameter("currentPage");
        String pageSize = req.getParameter("pageSize");
        Map<String,String> params = new HashMap<>();
        params.put("cname",cname);
        params.put("cstate",cstate);
        params.put("currentPage",currentPage);
        params.put("pageSize",pageSize);
        CollectionService collectionService = new CollectionServiceImpl();
        Page<Collection> page = collectionService.getPage(params);
        ResponseData data = ResponseData.ok(page);
        resp.getWriter().println(JSON.toJSONString(data));
    }
}
